package bandsInTownQuery;

import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.Iterator;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

public class BandsInTownSearch {

	public BandsInTownSearch(){}
	
	public Iterator<Event> getQueryResults(String query) {
		Iterator<Event> it = null;
		try {
			
			URL url = new URL("http://api.bandsintown.com/artists/"+query+"/events.xml");
			InputStream is = url.openStream();

			JAXBContext jc = JAXBContext.newInstance( "bandsInTownQuery" );
			Unmarshaller u = jc.createUnmarshaller();

			Events results = (Events)u.unmarshal( is );
	        
	        it = results.getEvent().iterator();
	         
		} catch( Exception e) {
			e.printStackTrace();
		}

		return it;
	}
}
